package crl.lottery.view
{
	import crl.lottery.model.vo.RotationVO;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	

	public class LotteryView extends Sprite
	{
		private var _skin:LotterySkin;
		
		private var pointer:Sprite;
		public var rotaPane:Sprite;
		public var startBtn:MovieClip;
		
		private var rotaBitmap:Bitmap;
		
		private var rotationvo:RotationVO;
		public var disabeFilter:Array;
		public var emptyFilter:Array;
		
		public var resultEffect:Loader;
		public function LotteryView()
		{
			rotationvo=new RotationVO();
			
			var mat:Array =[0.3086,0.6094,0.082,0,0,0.3086,0.6094,0.082,0,0,0.3086,0.6094,0.082,0,0,0,0,0,1,0];
			disabeFilter=[new ColorMatrixFilter(mat)];
			emptyFilter=[];
			
			this.skin=new LotterySkin();
		}
		
		protected function set skin(value:LotterySkin):void{
			_skin=value;
			
			_skin.x=-(_skin.width>>1);
			_skin.y=-(_skin.height>>1);
			
			
			trace(_skin.width,_skin.height)
			
			bindComponent();
			
			this.addChild(_skin);
			
			
			var alertContainer:Sprite=new Sprite();
			alertContainer.mouseEnabled=false;
			this.addChild(alertContainer);
			LAlert.container=alertContainer;
			
			this.resultEffect=new Loader();
			this.resultEffect.mouseEnabled=this.resultEffect.mouseChildren=false;
			this.addChild(resultEffect);
			
			
			alertContainer.x=resultEffect.x=int(_skin.x);
			alertContainer.y=resultEffect.y=int(_skin.y);
		}
		
		protected function bindComponent():void{
			
			pointer=_skin.pointer;
			rotaPane=_skin.rotaPane;
			rotaPane.cacheAsBitmap=true;
			rotaPane.x=int(rotaPane.x);
			rotaPane.y=int(rotaPane.y);
			
			var w:int=rotaPane.width;
			var h:int=rotaPane.height;
			var bitmapdata:BitmapData=new BitmapData(w,h,false,0);
			
			
			var rect:Rectangle=rotaPane.getBounds(rotaPane);
			
			var matrix:Matrix=new Matrix();
			matrix.tx=-rect.left;
			matrix.ty=-rect.top;
			
			bitmapdata.draw(rotaPane,matrix,null,null,null,true);
			rotaBitmap=new Bitmap(bitmapdata,"auto",true);
			
			rotaBitmap.x=-(w>>1);
			rotaBitmap.y=-(h>>1);
			while(rotaPane.numChildren){
				rotaPane.removeChildAt(0);
			}
			rotaPane.addChild(rotaBitmap);
			
			startBtn=_skin.startBtn;
			
			startBtn.buttonMode=true;
			startBtn.mouseChildren=false;
			
		}
	}
}